<%= search_form_for [:admin, @search], class: "filter-wrap", data: { controller: "filters" } do |f| %>
  <div class="d-flex flex-column flex-lg-row gap-2">
    <%= render 'spree/admin/shared/filters_search_bar', param: :email_cont, label: Spree.t(:email) %>

    <%= dropdown do %>
      <%= dropdown_toggle class: 'btn-light dropdown-toggle' do %>
        <span class="text-muted font-weight-normal mr-1">
          <%= Spree.t(:show) %>
        </span>
        <%# Show current filter value %>
        <% current_value =
          if params.dig(:q, :verified).to_s == 'true'
            Spree.t('admin.newsletter_subscribers.verified')
          elsif params.dig(:q, :unverified).to_s == 'true'
            Spree.t('admin.newsletter_subscribers.unverified')
          else
            Spree.t('admin.newsletter_subscribers.all')
          end
        %>
        <%= current_value %>
      <% end %>
      <%= dropdown_menu do %>
        <%= active_link_to Spree.t('admin.newsletter_subscribers.all'),
          params.to_unsafe_h.deep_merge(q: { verified: nil, unverified: nil }),
          class: 'dropdown-item',
          active: params.dig(:q, :verified).blank? && params.dig(:q, :unverified).blank? %>
        <%= active_link_to Spree.t('admin.newsletter_subscribers.verified'),
          params.to_unsafe_h.deep_merge(q: { verified: true, unverified: nil }),
          class: 'dropdown-item',
          active: params.dig(:q, :verified).to_s == 'true' %>
        <%= active_link_to Spree.t('admin.newsletter_subscribers.unverified'),
          params.to_unsafe_h.deep_merge(q: { verified: nil, unverified: true }),
          class: 'dropdown-item',
          active: params.dig(:q, :unverified).to_s == 'true' %>
      <% end %>
    <% end %>
  </div>

  <%= render "spree/admin/shared/filter_badge_template" %>
  <div data-filters-target="badgesContainer" class="filter-badges-container"></div>
<% end %>
